import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/utils/loading/loading_animation.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:get/get.dart';
import 'package:flutter_09_game/generated/locales.g.dart';

class BaseRefresh {
  static final _readyLoadWidget = Container(
    height: 50,
    alignment: Alignment.center,
    child: CustomPaint(
        size: const Size(28, 28), painter: ArcPainter(AppColor.primary)),
    // child: const AutoImage(Assets.refreshReadyLoad, width: 28),
  );
  static final _loadingWidget = Container(
    height: 50,
    alignment: Alignment.center,
    child: const LoadingAnimation(color: AppColor.primary),
    // child: const AutoImage(Assets.refreshLoading, width: 28),
  );

  static Widget _noMoreWidget({String? content}) {
    return Container(
      height: 50,
      alignment: Alignment.center,
      child: Text(content ?? LocaleKeys.noMoreData.tr,
          style:
              TextStyle(fontSize: 12.sp, color: Colors.black.withOpacity(0.4))),
    );
  }

  static CustomHeader buildCustomHeader() {
    return CustomHeader(
      builder: (BuildContext context, RefreshStatus? mode) {
        if (mode == RefreshStatus.idle) {
          return _readyLoadWidget;
        } else if (mode == RefreshStatus.canRefresh) {
          return _readyLoadWidget;
        } else if (mode == RefreshStatus.refreshing) {
          return _loadingWidget;
        } else if (mode == RefreshStatus.completed) {
          return _loadingWidget;
        } else if (mode == RefreshStatus.failed) {
          return _loadingWidget;
        } else {
          return Container();
        }
      },
    );
  }

  static CustomFooter buildCustomFooter({String? footerContent}) {
    return CustomFooter(
      builder: (BuildContext context, LoadStatus? mode) {
        if (mode == LoadStatus.idle) {
          return Container();
        } else if (mode == LoadStatus.canLoading) {
          return _readyLoadWidget;
        } else if (mode == LoadStatus.loading) {
          return _loadingWidget;
        } else if (mode == LoadStatus.noMore) {
          return _noMoreWidget(content: footerContent);
        } else if (mode == LoadStatus.failed) {
          return Container();
        } else {
          return Container();
        }
      },
    );
  }
}
